programming4us
           
 
 
SQL Server

SQL Server 2008 : Indexing for Performance - Putting It All Together (part 5) - Filtered Indexes

- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019
11/30/2010 3:41:46 PM

6. Filtered Indexes

For the last example, we would like to create a filtered index. Assume that the corporate office exists in territory 4, and you want all of your queries for the VIPs of the company to be extremely fast. For demonstration purposes, assume that the director of sales runs a daily report to see the number of sales and the Totaldue of sales for his region, and every time that query runs slowly, your boss gets a phone call. So instead of creating a nonclustered index on the Territory column, you're going to create a filtered index on the Territory column just for his area. The code in Listing 6 creates a nonclustered index on TerritoryID and a filtered nonclustered index for territory 4.

Example 6. SQL Script That Creates a Filtered Index
CREATE NONCLUSTERED INDEX ix_Territory ON
apWriter.SalesOrderHeader(TerritoryID) INCLUDE (OrderDate,TotalDue)

CREATE NONCLUSTERED INDEX ix_TerritoryFiltered
ON apWriter.SalesOrderHeader(TerritoryID) INCLUDE (OrderDate,TotalDue)
WHERE TerritoryID = 4

GO

SELECT SalesOrderId, OrderDate,TotalDue
FROM apWriter.SalesOrderHeader soh WITH(index(ix_Territory))
WHERE TerritoryID = 4

SELECT SalesOrderId, OrderDate,TotalDue
FROM apWriter.SalesOrderHeader soh WITH (index(ix_TerritoryFiltered))
WHERE TerritoryID = 4

The listing queries the SalesOrderHeader table for a particular territory. The execution plan will show the difference between a filtered index and a nonclustered index. The execution plan of Listing 6 is shown in Figure 11. After reviewing the execution plan, you can easily see the benefit of using filtered indexes instead of just nonclustered indexes.

Figure 11. The performance benefit of using a filtered index compared to a nonclustered index

Other -----------------
- SQL Server Integration Services : Logged and Nonlogged Operations
- SQL Server Integration Services : Using bcp (part 5)
- SQL Server Integration Services : Using bcp (part 4)
- SQL Server Integration Services : Using bcp (part 3)
- SQL Server Integration Services : Using bcp (part 2) - Fundamentals of Exporting and Importing Data
- SQL Server Integration Services : Using bcp (part 1)
- SQL Server Integration Services : Connection Projects in Visual Studio
- SQL Server Integration Services : The Package Execution Utility (part 3) - The dtutil Utility
- SQL Server Integration Services : The Package Execution Utility (part 2) - Running Packages
- SQL Server Integration Services : The Package Execution Utility (part 1)
- SQL Server Integration Services : The SSIS Designer
- SQL Server Integration Services : Running the SSIS Wizard
- SQL Server Integration Services : A Data Transformation Requirement
- SQL Server 2008 : SSIS Tools and Utilities
- SQL Server 2008 : SSIS Architecture and Concepts
- SQL Server 2008 : SQL Server Integration Services - SSIS Basics
- Defensive Error Handling : Using Transactions and XACT_ABORT to Handle Errors
- Managing Security Within the Database Engine : Securables
- Managing Security Within the Database Engine : Database Security
- Managing Security Within the Database Engine : Creating SQL Server Principals
 
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
- First look: Apple Watch

- 3 Tips for Maintaining Your Cell Phone Battery (part 1)

- 3 Tips for Maintaining Your Cell Phone Battery (part 2)
programming4us programming4us